<?php
/**

 */
define('IN_DOUCO', true);

// 强制在移动端中显示PC版
if (isset($_REQUEST['mobile'])) {
   setcookie('client', 'pc');
   if ($_COOKIE['client'] != 'pc') $_COOKIE['client'] = 'pc';
}

require (dirname(__FILE__) . '/include/init.php');


if ($_REQUEST['lang']) {
    $lang = $_REQUEST['lang'];
}else{
    $lang = 'zh';
}
require (dirname(__FILE__) . '/common.php');

$smarty->assign('dangqun_url', get_dangqun($lang));
$smarty->assign('zhaosheng_url', get_zhaosheng($lang));

if ($_REQUEST['type']) {
    $type = $_REQUEST['type'];
}else{
    $type = '0';
}

if ($_REQUEST['cat_id']){
    $cat_id = $_REQUEST['cat_id'];
}else{
    $cat_id = '2';
}

$where = ' WHERE cat_id IN (' . $cat_id . ') and lang=\''. $lang.'\'';
if ($type == 1){
    
    // 获取分页信息
    $page = $check->is_number($_REQUEST['page']) ? trim($_REQUEST['page']) : 1;
    list($limit,$product_num,$sqlexp) = $dou->pager2('product', ($_DISPLAY['product'] ? $_DISPLAY['product'] : 10), $page, $dou->rewrite_url('info', $cat_id), $where);

    /* 获取文章列表 */
    $sql = "SELECT id, name, image, cat_id,url FROM " . $dou->table('product') . $where . " ORDER BY sort ASC, name" . $limit;
    $query = $dou->query($sql);

    while ($row = $dou->fetch_array($query)) {
        // if ($cat_id == '6'){
        //     $url = $row['url'];
        // }else{
        //     $url = 'info.php?type=1&id='.$row['id'];
        // }
        $url = 'info.php?type=1&id='.$row['id'];

        $image = $row['image'] ? ROOT_URL . $row['image'] : '';
        
        $product_list[] = array (
                "id" => $row['id'],
                "cat_id" => $row['cat_id'],
                "name" => $row['name'],
                "image" => $image,
                "url" => $url 
        );
    }

    $smarty->assign('objs', $product_list);
    $smarty->assign('obj_num', $product_num);
}else{
    // 获取分页信息
    $page = $check->is_number($_REQUEST['page']) ? trim($_REQUEST['page']) : 1;
    list($limit,$article_num,$sqlexp) = $dou->pager2('article', ($_DISPLAY['article'] ? $_DISPLAY['article'] : 10), $page, $dou->rewrite_url('info', $cat_id), $where);

    $sql = "SELECT id, title, image, cat_id, url FROM " . $dou->table('article') . $where . " ORDER BY sort ASC, title" . $limit;
    $query = $dou->query($sql);

    while ($row = $dou->fetch_array($query)) {
        if ($cat_id == '8'){
            $url = $row['url'];
        }else{
            $url = 'info.php?id='.$row['id'];
        }
        $image = $row['image'] ? ROOT_URL . $row['image'] : '';
        
        $article_list[] = array (
                "id" => $row['id'],
                "cat_id" => $row['cat_id'],
                "name" => $row['title'],
                "image" => $image,
                "url" => $url
        );
    }
    $smarty->assign('objs', $article_list);
    $smarty->assign('obj_num', $article_num);
}

$smarty->assign('lang', $lang);


// 赋值给模板-数据
$smarty->display('list_img_name.dwt');

?>
